<template>
  <div id="all">
    <div id="container2"></div>;

  </div>
</template>

<script>
import LogicFlow from "@logicflow/core";
import "@logicflow/core/dist/style/index.css";
// 矩形
import { RectNode, RectNodeModel } from "@logicflow/core";
// 圆形
import { CircleNode, CircleNodeModel } from "@logicflow/core";
// 椭圆
import { EllipseNode, EllipseNodeModel } from "@logicflow/core";
// 多边形
import { PolygonNode, PolygonNodeModel } from "@logicflow/core";
// 菱形
import { DiamondNode, DiamondNodeModel } from "@logicflow/core";
// 文本
import { TextNode, TextNodeModel } from "@logicflow/core";
// HTML
import { HtmlNode, HtmlNodeModel } from "@logicflow/core";
//自定义
import { RectResize } from "@logicflow/extension";
class CustomNodeModel extends RectResize.model {}
class CustomNode extends RectResize.view {}
import UserTask from "../mock/LogicFlow/UserTaskNode.js";
import customRect from "../mock/LogicFlow/customNode";
import SquareModel from "../mock/LogicFlow/SquareNode.js";
import textNode from "../mock/LogicFlow/textNode.js";

export default {
  name: "",
  components: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  // 生命周期 - 载入后, Vue 实例挂载到实际的 DOM 操作完成，一般在该过程进行 Ajax 交互
  mounted() {
    this.init();
  },
  data() {
    return {};
  },
  methods: {
    init() {
      const data = {
        // 节点
        nodes: [
          {
            id: "node_id_1",
            type: "rect",
            x: 100,
            y: 100,
            text: { x: 100, y: 100, value: "节点1" },
            properties: {},
          },
          {
            id: "node_id_2",
            type: "circle",
            x: 200,
            y: 300,
            text: { x: 300, y: 300, value: "节点2" },
            properties: {},
          },
        ],
        edges: [
          {
            id: "edge_id",
            type: "polyline",
            sourceNodeId: "node_id_1",
            targetNodeId: "node_id_2",
            text: { x: 139, y: 200, value: "连线" },
            startPoint: { x: 100, y: 140 },
            endPoint: { x: 200, y: 250 },
            pointsList: [
              { x: 100, y: 140 },
              { x: 100, y: 200 },
              { x: 200, y: 200 },
              { x: 200, y: 250 },
            ],
            properties: {},
          },
        ],
      };
      let width = document.body.clientWidth; //网页可见区域宽：
      let height = document.body.clientHeight; //网页可见区域高：
      // 渲染画布
      const lf = new LogicFlow({
        container: document.querySelector("#container2"),
        width,
        height,
      });
      lf.register(UserTask); //引入自定义模块
      lf.register(customRect); //引入自定义形状
      lf.register(SquareModel); //引入自定义锚点
      lf.register(textNode); //引入自定义文本节点

      // lf.render(data);
      lf.render({
        nodes: [
          {
            id: "UserTask",
            type: "UserTask",
            x: 100,
            y: 100,
            text: { x: 100, y: 100, value: "我是自定义节点" },
          },
          {
            id: "customRect",
            type: "customRect",
            x: 300,
            y: 100,
            text: { x: 300, y: 100, value: "我是自定义形状" },
          },
          {
            id: "SquareModel",
            type: "SquareModel",
            x: 300,
            y: 300,
            text: { x: 300, y: 300, value: "我是自定义锚点\n只能右边连接" },
          },
          {
            id: "textNode",
            type: "textNode",
            x: 400,
            y: 400,
            isSelected: true,
            text: {
              x: 400,
              y: 400,
              value: "不允许文本被编辑\n字体红色",
            },
          },
        ],
        edges: [
          {
            type: "polyline",
            sourceNodeId: "UserTask",
            targetNodeId: "customRect",
          },
          {
            type: "polyline",
            sourceNodeId: "SquareModel",
            targetNodeId: "UserTask",
          },
        ],
      });
    },
  },
};
</script>

<style scoped="scoped">
.containers {
  position: absolute;
  background-color: #ffffff;
  width: 100%;
  height: 100%;
  border: 1px solid #e3e3e3;
}
.canvas {
  width: 100%;
  height: 100%;
}
.panel {
  position: absolute;
  right: 0;
  top: 0;
  width: 300px;
}
.lf-graph {
  border: 1px solid;
}
</style>
